<extend name="Public/base"/>
<block name="style" >
    <link rel="stylesheet" href="__STATIC__/styles/vendors/bootstrap-table.css">
    <link rel="stylesheet" href="__STATIC__/styles/feedback_manage.css">
    <link rel="stylesheet" href="__STATIC__/styles/vendors/bootstrap-select.min.css">
</block>
<block name="content">
    <div id="toolbar">
        <button id="mark" class="btn btn-primary btn-flat">
            标为已读
        </button>
        <button id="remove" class="btn btn-danger btn-flat" disabled>
            <i class="glyphicon glyphicon-remove"></i>删除
        </button>
    </div>

    <table id="table" data-toolbar="#toolbar">
    </table>

    <div class="modal fade" id="confirm_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">确认</h4>
                </div>
                <div class="modal-body">
                    确定要删除吗?
                </div>
                <div class="modal-footer">
                    <button id="confirmDel" type="button" class="btn btn-danger btn-flat">删除</button>
                    <button type="button" class="btn btn-default btn-flat" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="feedback_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body">
                    <div id="feedback-text">
                        <label>反馈内容: <span id="content"></span></label>
                    </div>
                    <p class="row">
              <span class="col-lg-7 col-md-7 col-sm-7 col-xs-7">
                <label>反馈人:<span id="real_name"></span></label>
              </span>
                        <span class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
                <label>反馈时间:<span id="create_time"></span></label>
              </span>
                    </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default btn-flat" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>

</block>

<block name="script">
    <script src="__STATIC__/scripts/vendors/bootstrap-select.min.js"></script>
    <script src="__STATIC__/scripts/vendors/bootstrap-table.js"></script>
    <script>
        var $table = $('#table');
        var $remove = $('#remove');
        var $mark = $('#mark');
        var $complexModal = $('#feedback_modal');
        var $confirmModal = $('#confirm_modal');





        var TableInit = function(){
            var oTableInit = new Object();

            oTableInit.selections = [];


            oTableInit.init = function(){
                $table.bootstrapTable({
                    formatLoadingMessage: function () {
                        return '正在努力地加载数据中，请稍候……';
                    },
                    formatRecordsPerPage: function (pageNumber) {
                        return '每页显示 ' + pageNumber + ' 条记录';
                    },
                    formatShowingRows: function (pageFrom, pageTo, totalRows) {
                        return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
                    },
                    formatSearch: function () {
                        return '搜索';
                    },
                    formatNoMatches: function () {
                        return '没有找到匹配的记录';
                    },
                    formatPaginationSwitch: function () {
                        return '隐藏/显示分页';
                    },
                    formatRefresh: function () {
                        return '刷新';
                    },
                    formatToggle: function () {
                        return '切换';
                    },
                    formatColumns: function () {
                        return '列';
                    },
                    url:"{:U('feedbackList')}",
                    method:'get',
                    striped:true,
                    cache:false,
                    pagination:true,
                    sortable:false,
                    sortOrder:'asc',
                    sidePagination:'server',
                    queryParams:oTableInit.queryParams,
                    pageNumber:1,
                    pageSize:10,
                    pageList:[10,20,50],
                    uniqueId:'opinion_feedback_id',
                    search:true,
                    height:getHeight(),


                    columns:[
                        {
                            checkbox:true,
                            align:'center'
                        },

                        {
                            field:'content',
                            title:'反馈内容',
                            formatter:function (value){
                                return '<a href="javascript: void 0" class="content">' + value + '</a>';
                            },
                            events:operateEvents
                        },
                        {
                            field:'real_name',
                            title:'反馈人'
                        },
                        {
                            field:'create_time',
                            title:'反馈时间'
                        },
                        {
                            field:'state',
                            title:'状态',
                            formatter:function (value){
                                if(value == 1){
                                    return '已读';
                                }else{
                                    return '未读';
                                }
                            }
                        }
                    ]
                });


                $(window).resize(function () {
                    $table.bootstrapTable('resetView',{height: getHeight()});
                });

                $table.on('check.bs.table uncheck.bs.table ' +
                        'check-all.bs.table uncheck-all.bs.table', function () {
                    $('#remove').prop('disabled', !$table.bootstrapTable('getSelections').length);

                    // save your data, here just save the current page
                    oTableInit.selections = oTableInit.getIdSelections();
                    // push or splice the selections if you want to save all data selections
                });


            };

            oTableInit.queryParams = function(params){
                var temp = {
                    limit:params.limit,
                    offset:params.offset,
                    search:params.search
                };
                return temp;
            };


            oTableInit.getIdSelections = function(){
                return $.map($table.bootstrapTable('getSelections'), function (row) {
                    return row.opinion_feedback_id;
                })
            };

            return oTableInit;
        };

        function getHeight() {
            return $("#right").height();
        }

        function initComplexModal(data){
            for(var p in data){
                if(typeof(data[p]) != "function"){
                    $complexModal.find('#' + p).text(data[p]) ;
                }
            }
        }

        window.operateEvents = {
            'click .content':function(e, value, row, index){
                $complexModal.modal('show');
                initComplexModal(row);
            }
        };

        $(function () {


            var oTable = new TableInit();
            oTable.init();

            $remove.click(function () {
                $("#confirm_modal").modal('show');
            });

            $('#confirmDel').click(function () {
                $confirmModal.modal('hide');

                $.post({
                    url:"{:U('delete')}",
                    data:{
                        selectedIds : oTable.selections
                    },
                    success:function(data){
                        if(data.status == 1){
                            layer.msg('删除成功');
                            $table.bootstrapTable('refresh');
                        }else{
                            layer.msg(data.msg);
                        }
                    }
                })

            });

            $mark.click(function () {
                if(oTable.selections && oTable.selections.length > 0){
                    $.post({
                        url:"{:U('setRead')}",
                        data:{
                            selectedIds : oTable.selections
                        },
                        success:function(data){
                            if(data.status == 1){
                                layer.msg('更新成功');
                                $table.bootstrapTable('refresh');
                            }else{
                                layer.msg(data.msg);
                            }
                        }
                    })
                }else{
                    layer.msg('请至少选择一项');
                }
            })

        });


    </script>
</block>